﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace GraphDrawer {
	public partial class DatabaseNetworkSelector : UserControl {
		public string graphML;

		private IWizardController wc;
		private DataProvider.DataProviderServiceSoapClient cl = new DataProvider.DataProviderServiceSoapClient();
		private GraphProvider.GraphProviderServiceSoapClient graphProvider;

		public DatabaseNetworkSelector(GraphProvider.GraphProviderServiceSoapClient graphProvider, IWizardController wc) {
			InitializeComponent();

			this.graphProvider = graphProvider;
			this.wc = wc;
			Description.Text = Resource.DatabaseNetworkSelector;

			cl.GetAvailableNetsCompleted +=
				new EventHandler<DataProvider.GetAvailableNetsCompletedEventArgs>
					(cl_GetAvailableNetsCompleted);

			graphProvider.netToGraphmlCompleted +=
				new EventHandler<GraphProvider.netToGraphmlCompletedEventArgs>
					(graphProvider_netToGraphmlCompleted);

			cl.GetAvailableNetsAsync();
		}

		public void Init() {
			if (networksBox.Items.Count > 0)
				wc.PopUp.btnOk.IsEnabled = true;
		}

		void cl_GetAvailableNetsCompleted(object sender, DataProvider.GetAvailableNetsCompletedEventArgs e) {
			networksBox.Items.Clear();

			foreach (var item in e.Result)
				networksBox.Items.Add(item);

			if (networksBox.Items.Count > 0)
				networksBox.SelectedItem = networksBox.Items[0];
		}

		void graphProvider_netToGraphmlCompleted(object sender, GraphProvider.netToGraphmlCompletedEventArgs e) {
			graphML = e.Result;
			//networkDescription.Text = e.Result[1];
		}

		private void NetworksBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
			if (networksBox.SelectedItem != null)
				graphProvider.netToGraphmlAsync(networksBox.SelectedItem.ToString());
		}
	}
}
